package com.javen.bankpay;

import java.util.List;

import com.jfinal.log.Log;
import com.jfinal.plugin.activerecord.Record;

public class MainLoopCheck extends Thread{
	
	static Log log = Log.getLog(MainLoopCheck.class);
	static PayInterfaceService payInterfaceService = new PayInterfaceService();

	
	@Override
	public void run(){
		
		while (true)
		{
			try{
				checkReduceFee();
			} catch (Exception e) {
				log.error(e.getMessage(),e);
			}
			
			try {
				Thread.sleep(300000);
			} catch (InterruptedException e) {
				log.error(e.getMessage(),e);
			}
			
		}
	}
	
	public void checkReduceFee(){
		List<Record> debitCards = payInterfaceService.getCards("debit_card", "", "getReduce");
		if(debitCards.size() > 0){
			String parOpenId = "";
			for(Record debitCard : debitCards){
				parOpenId = debitCard.getStr("parOpenId");
				 List<Record> result1 = payInterfaceService.getDebits(parOpenId);
				if ((result1!=null)&&(result1.size()>0))
				{
					Record parDebit =result1.get(0);
					if(parDebit != null){
						if(parDebit.getDouble("fee0") > 3.9){
							PayInterfaceController.changeDebit(debitCard, parDebit, "");
						}
					}
				}
			}
		}
	}
	
}
